export default {
	// 用户 token
	token: false,
	// 用户信息
	userinfo: false,
	// 权限验证跳转
	navigate(options, type = 'navigateTo') {
		// 权限验证
		if (!this.token) {
			return uni.navigateTo({ url: '/pages/login/login' })
		}
		// 跳转
		switch (type) {
			case 'navigateTo':
				uni.navigateTo({ options });
				break;
			case 'navigateTo':
				uni.redirectTo({ options });
				break;
			case 'reLaunch':
				uni.reLaunch({ options });
				break;
			case 'switchTab':
				uni.switchTab({ options });
				break;				
			default:
				break;
		}
	},
	// userinfo格式转换  171
	__formatUserinfo(obj){
		// 手机/邮箱/账号登录
		if (obj.logintype == "username" || obj.logintype == "email" || obj.logintype == "phone") {
			// 设置默认头像
			obj.userpic = obj.userpic || "https://krplus-pic.b0.upaiyun.com/avatar/201812/28095646/fde0v5pcswzft2s8!120";
			return obj;
		}
		// 第三方登录（已绑定）
		if (obj.user && obj.user_id > 0) {
			return {
				id: obj.user.id,
				username: obj.user.username || obj.nickname,
				userpic: obj.user.userpic || obj.avatarurl,
				phone: obj.user.phone,
				email: obj.user.email,
				status: obj.user.status,
				create_time: obj.user.create_time,
				logintype: obj.logintype,
				password:obj.user.password,
				token: obj.token,
				userinfo: {
				    id: obj.user.userinfo.id,
				    user_id: obj.user.userinfo.user_id,
				    age: obj.user.userinfo.age,
				    sex: obj.user.userinfo.sex,
				    qg: obj.user.userinfo.qg,
				    job: obj.user.userinfo.job,
				    path: obj.user.userinfo.path,
				    birthday: obj.user.userinfo.birthday,
				}
			}
		}
		// 第三方登录（未绑定）
		return {
			id: obj.user_id,
			username: obj.nickname,
			userpic: obj.avatarurl,
			phone: false,
			email: false,
			status: 1,
			create_time: false,
			logintype: obj.logintype,
			token: obj.token,
			userinfo: false
		}
	},
}